<?php
include_once XXF_RUNEXCEL;
class Pxy_list_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $this::sessver();
        $type=!empty($_POST['type'])?$_POST['type']:false;
        if(!empty($xxfget['type'])){$type=$xxfget['type'];}
        if(!$type){
            $pid=$xxfget['pid'];
        	$result=xdb::getInstance()->getarray('select * from peixunxueyuan where pid='.$pid);
        	$pname=xdb::getInstance()->getvar('select pname from peixunban where id='.$pid);
        	$zyfzr=xdb::getInstance()->getvar('select count(1) from peixunxueyuan where ptype like "%负责人%" and pid='.$pid);
        	$aqglry=xdb::getInstance()->getvar('select count(1) from peixunxueyuan where ptype like "%管理人员%" and pid='.$pid);
        	$this::show('pxy_list',compact('result','pname','pid','zyfzr','aqglry'));
        }elseif($type=="upchengji"){
            $pid=$_POST['pid'];
            $targetPath = XXF_ROOT.'html\\uploader\\xlsx'; // 指定的保存目录
            if (!empty($_FILES)) {
                $tempFile = $_FILES['file']['tmp_name'];
                $fileTypes = array('xls'); // File extensions
                $fileParts = pathinfo($_FILES['file']['name']);
                $targetFile = rtrim($targetPath,'/') . '\\' . time().rand(10,99).".".$fileParts['extension'];
                if (in_array($fileParts['extension'],$fileTypes)) {
                    move_uploaded_file($tempFile,$targetFile);//保存文件到指定目录
                    $PHPExcelReader = new PHPExcel_Reader_Excel5();
                    $PHPExcel=$PHPExcelReader->load($targetFile);
                    $es = $PHPExcel->getSheet(0);
                    $allCol = $es->getHighestColumn();
                    $allRow = $es->getHighestRow();
                    //下面开始判断表是否正确，正确后添加成绩信息
                    if((($es->getCell('E1'))=="身份证号")&&(($es->getCell('L1'))=="知识成绩")){
                        $array=array();
                        $array2=array();
                        for($i=2;$i<=$allRow;$i++){
                            $array['chengji']=$es->getCell('L'.$i);
                            $array['bukaochengji']=$es->getCell('M'.$i);
                            $array2['idcard']=$es->getCell('E'.$i);
                            $array2['pid']=$pid;
                            xdb::getInstance()->updb("peixunxueyuan", $array, $array2);
                        }
                        echo 1;
                    }else{
                        echo 0;
                    }
                }
            }
        }elseif($type=="uppic"){
            $targetPath = XXF_ROOT.'html\\uploader\\xueyuanimg'; // 指定的保存目录
            if (!empty($_FILES)) {
                $tempFile = $_FILES['file']['tmp_name'];
                //$aid=$_POST['id'];
                $fileTypes = array('jpg'); // File extensions
                $fileParts = pathinfo($_FILES['file']['name']);
                $targetFile = rtrim($targetPath,'/') . '\\' .$fileParts['basename'];
                if (in_array($fileParts['extension'],$fileTypes)) {
                    $filename=rtrim($fileParts['basename'],'.'.$fileParts['extension']);
                    //$id=xdb::getInstance()->getvar("select id from students where idcard='$filename'");
                    if(_checkIdCard($filename)){
                        move_uploaded_file($tempFile,$targetFile);//保存文件到指定目录
                        //$array=array();$array2=array();
                        //$array['picstatus']='1';
                        //$array2['id']=$id;
                        //xdb::getInstance()->updb('students', $array, $array2);
                        echo 1;
                    }else{
                        echo 0;
                    }
                }
            }
        }elseif($type=="pxchengjitemp"){
            $xls=new RunExcel();
            $xls->fromExcel(XXF_ROOT.'html\\uploader\\moban\\peixunchengjiupload.xls');
            $xls->down("chengjitemp");
        }
    }
}